<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>元素属性</title>
</head>

<body>
    <div id="div1" class="myborder" style="color: red" title="div1">
        <p>元素属性操作</p>
    </div>
    <script>
        //JS 对元素属性的处理
        var div1 = document.getElementById("div1");
        div1.title = "xxxx"
        div1.style.color = "blue"
        div1.style.backgroundColor = "green"

        //JS 对元素属性处理方式二
        div1.setAttribute("title", "yyyy") //前一个属性名，后一个设置内容
        div1.getAttribute("title") //获取元素属性
    </script>
</body>

</html>